#include "widget.h"
#include "ui_widget.h"
#include "mytcpserver.h"

#include <QByteArray>
#include <QFile>
#include <QDebug>
#include <QMessageBox>
#include <QHostAddress>
#include <qmessagebox.h>
Widget::Widget(QWidget *parent)
    : QWidget(parent)
    , ui(new Ui::Widget)
{
    ui->setupUi(this);
    loadConfig();
    //设置监听
    bool ret= myTcpServer::getInstance().listen(QHostAddress(m_strIp),m_usPort);

    qDebug()<<m_strIp<<m_usPort;
    if(ret==true)
    {
        qDebug()<<"监听客服成功！"<<endl;
    }
    else
    {
        qDebug()<<"监听失败！";
    }
}


void Widget::loadConfig()
{
    QFile file(":/server.config");
    if(file.open(QIODevice::ReadOnly))
    {
        QByteArray baData=file.readAll();//所有数据
        QString strData=baData.toStdString().c_str();//获取数据的首地址
        strData.replace("\r\n", " ");
        QStringList strList=strData.split(" ");
        m_strIp=strList.at(0);
        m_usPort=strList.at(1).toUShort();
        qDebug()<<"ip"<<m_strIp<<"port:"<<m_usPort;
    }
    else
    {
        QMessageBox::critical(this,"open config","open config faild");
    }
}

Widget::~Widget()
{
    delete ui;
}

